package services

import (
	"context"
	"dawncloud/models"

	"github.com/go-kit/kit/endpoint"
	"gorm.io/gorm"
)

type SewageService interface {
	GetSewageData(ctx context.Context) ([]models.SewageData, error)
}

type sewageServiceImpl struct {
	db *gorm.DB
}

func (s *sewageServiceImpl) GetSewageData(ctx context.Context) ([]models.SewageData, error) {
	var data []models.SewageData
	err := s.db.Find(&data).Error
	return data, err
}

func NewSewageService(db *gorm.DB) SewageService {
	return &sewageServiceImpl{db: db}
}

func MakeGetSewageDataEndpoint(s SewageService) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (interface{}, error) {
		data, err := s.GetSewageData(ctx)
		return data, err
	}
}

func MakeEndpoints(s SewageService) Endpoints {
	return Endpoints{
		GetSewageDataEndpoint: MakeGetSewageDataEndpoint(s),
	}
}

type Endpoints struct {
	GetSewageDataEndpoint endpoint.Endpoint
}
